package com.gosophia.dataDictionary.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseAjaxAction;
import com.gosophia.dataDictionary.dto.DataEntryDTO;
import com.gosophia.dataDictionary.dto.DataValueDTO;
import com.gosophia.dataDictionary.ws.DataDictionaryWebService;

/**
 * 查询词条下数据值
 * 
 * @author tianchunyu
 */
@Controller
@Scope("prototype")
public class FindDataValuesByEntryIdAction extends BaseAjaxAction<DataValueDTO> {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private String entryId;

    @Autowired
    private DataDictionaryWebService dataDictionaryWebService;
    
    private List<DataValueDTO> dataValueDtos;
    

    @Override
    public String _execute() throws Exception {
        DataEntryDTO dataEntryDto = dataDictionaryWebService
                .findDataEntryByDataEntryId(Long.valueOf(entryId));
        if (dataEntryDto != null) {
            dataValueDtos = dataEntryDto.getDataValues();
            if (dataValueDtos == null || dataValueDtos.size() == 0) {
                super.getRequestResult().setRsltCode("1");
            }else{
                super.getRequestResult().setRsltCode("0");
            }
        }

        return SUCCESS;
    }

    public String getEntryId() {
        return entryId;
    }

    public void setEntryId(String entryId) {
        this.entryId = entryId;
    }
    
    @Override
    public DataValueDTO getDetailData() {
        if (this.detailData == null) {
            this.detailData = new DataValueDTO();
        }
        return this.detailData;
    }

    public List<DataValueDTO> getDataValueDtos() {
        return dataValueDtos;
    }

    public void setDataValueDtos(List<DataValueDTO> dataValueDtos) {
        this.dataValueDtos = dataValueDtos;
    }

}
